package com.lwp.controller;
import java.util.Date;

import com.lwp.TestService;
import com.lwp.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * TestController
 *
 * @author lanwenping
 * @version 1.0
 * @date 2020/5/30 14:09
 */
@Controller
public class TestController {

    /** request response httpSession 都是线程安全的*/
    @Autowired
    HttpServletRequest request;
    @Autowired
    HttpServletResponse response;
    @Autowired
    HttpSession httpSession;

    @Autowired
    TestService testService;

    // properties需要在扫描的那个xml中存在，其他文件中存在不加载配置
    @Value("${mysql.url}")
    String mysqlUrl;
    // mysql.noVal 不存在的值抛出异常
//    @Value("${mysql.noVal:aaa123}")
//    String noVal;

    @GetMapping("/test")
    public String test(String name) {
        User user = new User();

        System.out.println(request);
        System.out.println(mysqlUrl);
        System.out.println(11111);
        new ModelAndView("index");
        return "index";
//        return
    }

    @ResponseBody
    @GetMapping("/test1")
    public String test1(String name) {
        User user = new User();

        System.out.println(request);
        System.out.println(mysqlUrl);
        System.out.println(11111);
        testService.updateUser2();
        return "index";
//        return
    }
}
